<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" media="screen" href="../../css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" media="screen" href="../../layui/css/layui.css">
</head>
<body>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
	<form class="form-horizontal" onsubmit="return false" id="form">
		<fieldset>
			<input type="hidden" id="id" name="id">
			<div class='form-group'>
				<label class='col-md-2 control-label'>图片上传</label>
				<div class='col-md-10'>
					<button type="button" class="layui-btn" id="test1">
						<i class="layui-icon">&#xe67c;</i>上传图片
					</button>
				</div>

				<input class='form-control' placeholder='imageId' type='hidden' name='imageId' id='imageId'
					   data-bv-notempty='true' data-bv-notempty-message='imageId 不能为空'>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>图片</label>
				<div class='col-md-10'>
					<img id='imgUrl' height="120" width="120"/>
				</div>
			</div>


			<input class='form-control' placeholder='path' type='hidden' name='path' id='path' data-bv-notempty='true'
				   data-bv-notempty-message='请上传图片'>
			<input class='form-control' placeholder='url' type='hidden' name='url' id='url' data-bv-notempty='true'
				   data-bv-notempty-message='请上传图片'>

			<div class='form-group'>
				<label class='col-md-2 control-label'>排序</label>
				<div class='col-md-10'>
					<input class='form-control' placeholder='order' type='text' name='order' id='order' data-bv-notempty='true' data-bv-notempty-message='order 不能为空'>
				</div>
			</div>

			<div class='form-group'>
				<label class='col-md-2 control-label'>服务类型：</label>
				<div class='col-md-10'>
					<select name="serviceType" class="form-control input-sm" id="serviceType">
					</select>
				</div>
			</div>

			<div class='form-group'>
				<label class='col-md-2 control-label'>广告分类：</label>
				<div class='col-md-10'>
					<select name="advertisingType" class="form-control input-sm" id="advertisingType">
						<option value="">请选择</option>
						<option value="0">用户端</option>
						<option value="1">律师端</option>
					</select>
				</div>
			</div>

			<div class='form-group'>
				<label class='col-md-2 control-label'>跳转参数（url以外填写数据id）</label>
				<div class='col-md-10'>
					<input class='form-control' placeholder='skipUrl' type='text' name='skipUrl' id='skipUrl' data-bv-notempty='false' data-bv-notempty-message='skipUrl 不能为空'>
				</div>
			</div>



			<div class="form-actions">
				<div class="row" align="center">
					<div class="col-md-12">
					    <button class="btn btn-primary" onclick="location.href='mfflAdvertisingList.html'">返回</button>
						<button class="btn btn-primary" type="submit" onclick="update()">
							<i class="fa fa-save"></i> 保存
						</button>
					</div>
				</div>
			</div>

		</fieldset>
	</form>
</div>
	<script type="text/javascript" src="../../js/libs/jquery-2.1.1.min.js"></script>
	<script type="text/javascript" src="../../js/jq.js"></script>
	<script type="text/javascript" src="../../js/plugin/bootstrapvalidator/bootstrapValidator.min.js"></script>
	<script type="text/javascript" src="../../js/common.js"></script>
	<script type="text/javascript" src="../../layui/layui.js"></script>
	<script type="text/javascript">
		layui.use(['layer','laydate'], function(){
		    var layer = layui.layer;
		});
		
		initData();
		
		function initData(){
			var id = getUrlParam("id");
			if(id != ""){
				$.ajax({
					type : 'get',
					url : '/mfflAdvertisings/'+id,
					async : false,
					success : function(data) {
						$('#id').val(data.id);
						$('#path').val(data.path);
						$('#url').val(data.url);
						$('#skipUrl').val(data.skipUrl);
						$('#order').val(data.order);
						$('#createTime').val(data.createTime);
                        $('#imgUrl').attr('src', '/statics' + data.url);

                        var serviceType = '';
                        serviceType += '<option value="0" ' + (data.serviceType == '0' ? 'selected' : '') + ' >外部链接</option>';
                        serviceType += '<option value="1" ' + (data.serviceType == '1' ? 'selected' : '') + ' >内部链接</option>';
                        serviceType += '<option value="2" ' + (data.serviceType == '2' ? 'selected' : '') + ' >律师详情</option>';
                        serviceType += '<option value="3" ' + (data.serviceType == '3' ? 'selected' : '') + ' >资讯</option>';
                        serviceType += '<option value="4" ' + (data.serviceType == '4' ? 'selected' : '') + ' >免费咨询</option>';
                        serviceType += '<option value="5" ' + (data.serviceType == '5' ? 'selected' : '') + ' >专业咨询</option>';
                        serviceType += '<option value="6" ' + (data.serviceType == '6' ? 'selected' : '') + ' >律师函</option>';
                        serviceType += '<option value="7" ' + (data.serviceType == '7' ? 'selected' : '') + ' >合同审核</option>';
                        serviceType += '<option value="8" ' + (data.serviceType == '8' ? 'selected' : '') + ' >合同定制</option>';
                        $('#serviceType').html(serviceType);

                        var advertisingType = '';
                        advertisingType += '<option value="0" ' + (data.advertisingType == '0' ? 'selected' : '') + ' >用户端</option>';
                        advertisingType += '<option value="1" ' + (data.advertisingType == '1' ? 'selected' : '') + ' >律师端</option>';
                        $('#advertisingType').html(advertisingType);

					}
				});
			}
		}

        layui.use('upload', function () {
            var upload = layui.upload;
            upload.render({
                elem: '#test1' //绑定元素
                , accept: 'file' //允许上传的文件类型
                , url: '/files/scAdvert' //上传接口
                , done: function (res, index, upload) {
                    console.log(res);
                    layer.msg("上传成功");
                    $('#path').val(res.path);
                    $('#url').val(res.url);
                    $('#imgUrl').attr('src', '/statics' + res.url);
                }
            });
        });

		function update() {
			$('#form').bootstrapValidator();
			var bootstrapValidator = $("#form").data('bootstrapValidator');
			bootstrapValidator.validate();
		    if(!bootstrapValidator.isValid()){
			   return;
		    }
		    
		    var formdata = $("#form").serializeObject();

			$.ajax({
				type : 'put',
				url : '/mfflAdvertisings',
				contentType: "application/json; charset=utf-8",  
				data : JSON.stringify(formdata),
				success : function(data) {
					layer.msg("修改成功", {shift: -1, time: 1000}, function(){
                        location.href = "mfflAdvertisingList.html";
                    });
				}
			});
		}
		
	</script>
</body>
</html>
